package basic.io;

import java.io.*;

//���Ƶ����ļ�
public class CopySingleFolder {

	public static void main(String[] args) throws IOException {
	    File  srcFile = new File("F:\\demo");
	    File  targetFile = new File("F:\\target");
	    if(!targetFile.exists()){
	    	targetFile.mkdirs();
	    }
	    File[] files = srcFile.listFiles();
	    for(int i=0;i<files.length;i++){
	    	String fileName=files[i].getName();//2.mp3
	    	System.out.println(fileName);
	    	File file = new File(targetFile,fileName);
	    	copyFile(files[i],file);
	    }
	    
	}
	public static void copyFile(File file,File newFile) throws IOException{
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
	    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile));
		
		byte[] by = new byte[1024];
		int len;
		while((len=bis.read(by))!=-1){
			bos.write(by,0,len);
		}
		
		bis.close();
		bos.close();
		
	}

}
